package com.ke.video_clip.lib

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.ke.video_clip.lib.databinding.VideoClipLibActivityVideoClipBinding
import com.ke.video_clip.lib.widget.VideoTrimListener

class VideoClipActivity : AppCompatActivity(), VideoTrimListener {

    private lateinit var binding: VideoClipLibActivityVideoClipBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = VideoClipLibActivityVideoClipBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.root.setOnTrimVideoListener(this)
        val request = intent.getParcelableExtra<ClipVideoRequest>(EXTRA_REQUEST)
        if (request == null) {
            onBackPressed()
            return
        }
        binding.root.init(request)
    }

    override fun onStartTrim() {


    }

    override fun onFinishTrim() {

        setResult(RESULT_OK)
        finish()
    }

    override fun onPause() {
        super.onPause()
        binding.root.onVideoPause()
        binding.root.setRestoreState(true)
    }

    override fun onCancel() {
        onBackPressed()

    }

    companion object {
        internal const val EXTRA_REQUEST = "EXTRA_REQUEST"
    }
}